package com.bird.dbtransfer.core;

import org.apache.commons.lang3.StringUtils;

import java.util.List;

public interface SqlTemplate {

    public String getSourceSelectSql();

    public String getTargetInsertSql();

    public List<SqlField>  getSqlFields();

    public String getSourceTableName();

    public String getTargetTableName();

    class SqlField{

        private String name;
        private String type;
        private int length;
        private String targetName;

        public SqlField() {
        }

        public SqlField(String name, String type, int length, String targetName) {
            this.name = name;
            this.type = type;
            this.length = length;
            this.targetName = targetName;
        }


        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getType() {
            if(StringUtils.isNotBlank(this.type)){
                int i = this.type.indexOf("(");
                if(i != -1){
                    return this.type.substring(0,i);
                }
            }
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        public int getLength() {
            return length;
        }

        public void setLength(int length) {
            this.length = length;
        }

        public String getTargetName() {
            return targetName;
        }

        public void setTargetName(String targetName) {
            this.targetName = targetName;
        }
    }

}
